import { defineStore } from 'pinia'
import $ajax from '@/api/to8010.js'

export const useAqiStore = defineStore('aqi', {
  state: () => ({
    aqiList: []
  }),
  getters: {
    so2MinNums() {
      return this.aqiList.map((item) => item.so2Min)
    },
    so2MaxNums() {
      return this.aqiList.map((item) => item.so2Max)
    },
    coMinNums() {
      return this.aqiList.map((item) => item.coMin)
    },
    coMaxNums() {
      return this.aqiList.map((item) => item.coMax)
    },
    spmMinNums() {
      return this.aqiList.map((item) => item.spmMin)
    },
    spmMaxNums() {
      return this.aqiList.map((item) => item.spmMax)
    },
    aqiMinNums() {
      return this.aqiList.map((item) => item.aqiMin)
    },
    aqiMaxNums() {
      return this.aqiList.map((item) => item.aqiMax)
    }
  },
  actions: {
    async getAqiList() {
      const path = '/aqi/select/all'
      const res = await $ajax.get(path)
      if (res !== null && res.code != null && res.code === 200) {
        this.aqiList = res.result
      }
    }
  }
})
